﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ControlIP.DataTypes.DomainObjects;
using dts = ControlIP.DataTypes;
using bs = ControlIp.Bussiness;
using com = ControlIpCommom;

namespace ControlIPApp
{
    /// <summary>
    /// Interaction logic for ucAddRegister.xaml
    /// </summary>
    public partial class ucAddRegister : UserControl
    {
        public ucAddRegister()
        {
            InitializeComponent();

            cboProject.ItemsSource = bs.Projects.GetDefaultProjects();
            cboProject.DisplayMemberPath = "Description";
            cboProject.SelectedValuePath = "Code";

            cboProject.SelectedValue = "INT005";
            datePicker1.DisplayDate = DateTime.Now;
            datePicker1.SelectedDate = DateTime.Now;


        }

        public ucAddRegister(int a) {
            InitializeComponent();
        }

        private void btAdd_Click(object sender, RoutedEventArgs e)
        {

            dts.DomainObjects.Entry ent = new Entry();
            ent.User = com.Global.GlobalCache.User;
            ent.Project = (dts.DomainObjects.Project)cboProject.SelectedItem;
            ent.Decription = txtDescr.Text;
            ent.TypeHour = chkFact.IsChecked != null && chkFact.IsChecked.Value? HourType.Billing : HourType.NotBilling;
            ent.TotalInHours = Int32.Parse( numHoras.Text);

            bool rs = bs.Entry.AddEntry(ent);

            if(rs)
                MessageBox.Show("Gravado com sucesso" ) ;
            else
                MessageBox.Show("Erro ao gravar a cena");

        }


        #region Marshall unMarshall cdo



        #endregion

    }
}
